---
layout: api
title: "v2.0.1 JavaScript Library: L.Util"
categories: api
version: v2.0.1
permalink: /api/v2.0.1/l-util/
---
<h2 id="util">Util</h2>

<p>Various utility functions, used by Leaflet internally.</p>

<h3>Methods</h3>

<table data-id='util'>
	<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
	</tr>
	<tr>
<td><code><b>extend</b>(
<nobr>&lt;Object&gt; <i>dest</i></nobr>,
<nobr>&lt;Object&gt; <i>src?..</i> )</nobr>
</code></td>

<td><code>Object</code></td>
<td>Merges the properties of the <code>src</code> object (or multiple objects) into <code>dest</code> object and returns the latter. Has an <code>L.extend</code> shortcut.</td>
	</tr>
	<tr>
<td><code><b>bind</b>(
<nobr>&lt;Function&gt; <i>fn</i></nobr>,
<nobr>&lt;Object&gt; <i>obj</i> )</nobr>
</code></td>

<td><code>Function</code></td>
<td>Returns a function which executes function <code>fn</code> with the given scope <code>obj</code> (so that <code><span class="keyword">this</span></code> keyword refers to <code>obj</code> inside the function code). Has an <code>L.bind</code> shortcut.</td>
	</tr>
	<tr>
<td><code><b>stamp</b>( &lt;Object&gt; <i>obj</i></nobr> )<nobr></code></td>
<td><code>String</code></td>
<td>Applies a unique key to the object and returns that key. Has an <code>L.stamp</code> shortcut.</td>
	</tr>
	<tr>
<td><code><b>requestAnimFrame</b>(
<nobr>&lt;Function&gt; <i>fn</i></nobr>,
<nobr>&lt;Object&gt; <i>context?</i></nobr>,
<nobr>&lt;Boolean&gt; <i>immediate?</i></nobr>,
<nobr>&lt;HTMLElement&gt; <i>element?</i> )</nobr>
</code></td>
<td><code>Number</code></td>
<td>Schedules <code>fn</code> to be executed when the browser repaints. When <code>immediate</code> is set, <code>fn</code> is called immediately if the browser doesn't have native support for <code>requestAnimationFrame</code>, otherwise it's delayed. Returns an id that can be used to cancel the request</td>
	</tr>
	<tr>
<td><code><b>cancelAnimFrame</b>(
<nobr>&lt;Number&gt; <i>id</i> )</nobr>
</code></td>
<td>-</td>
<td>Cancels a previous request to <code>requestAnimFrame</code>.</td>
	</tr>
	<tr>
<td><code><b>limitExecByInterval</b>(
<nobr>&lt;Function&gt; <i>fn</i></nobr>,
<nobr>&lt;Number&gt; <i>time</i></nobr>,
<nobr>&lt;Object&gt; <i>context?</i> )</nobr>
</code></td>

<td><code>Function</code></td>
<td>Returns a wrapper around the function <code>fn</code> that makes sure it's called not more often than a certain time interval <code>time</code>, but as fast as possible otherwise (for example, it is used for checking and requesting new tiles while dragging the map), optionally passing the scope (<code>context</code>) in which the function will be called.</td>
	</tr>

	<tr>
<td><code><b>falseFn</b>()</code></td>
<td><code>Function</code></td>
<td>Returns a function which always returns <code><span class="literal">false</span></code>.</td>
	</tr>
	<tr>
<td><code><b>formatNum</b>(
<nobr>&lt;Number&gt; <i>num</i></nobr>,
<nobr>&lt;Number&gt; <i>digits</i> )</nobr>
</code></td>

<td><code>Number</code></td>
<td>Returns the number <code>num</code> rounded to <code>digits</code> decimals.</td>
	</tr>
	<tr>
<td><code><b>splitWords</b>(
<nobr>&lt;String&gt; <i>str</i> )</nobr>
</code></td>

<td><code>String[]</code></td>
<td>Trims and splits the string on whitespace and returns the array of parts.</code></td>
	</tr>
	<tr>
<td><code><b>setOptions</b>(
<nobr>&lt;Object&gt; <i>obj</i></nobr>,
<nobr>&lt;Object&gt; <i>options</i> )</nobr>
</code></td>

<td><code>Object</code></td>
<td>Merges the given properties to the <code>options</code> of the <code>obj</code> object, returning the resulting options. See <a href="/mapbox.js/api/v2.0.1/l-class">Class options</a>. Has an <code>L.setOptions</code> shortcut.</td>
	</tr>
	<tr>
<td><code><b>getParamString</b>(
<nobr>&lt;Object&gt; <i>obj</i> )</nobr>
</code></td>

<td><code>String</code></td>
<td>Converts an object into a parameter URL string, e.g. <nobr><code>{a: "foo", b: "bar"}</code></nobr> translates to <code><span class="string">'?a=foo&amp;b=bar'</span></code>.</td>
	</tr>
	<tr id="util-template">
<td><code><b>template</b>(
<nobr>&lt;String&gt; <i>str</i>, &lt;Object&gt; <i>data</i> )</nobr>
</code></td>

<td><code>String</code></td>
<td>Simple templating facility, accepts a template string of the form <code><span class="string">'Hello {a}, {b}'</span></code> and a data object like <code>{a: 'foo', b: 'bar'}</code>, returns evaluated string (<code><span class="string">'Hello foo, bar'</span></code>). You can also specify functions instead of strings for data values &mdash; they will be evaluated passing <code>data</code> as an argument.</td>
	</tr>
	<tr>
<td><code><b>isArray</b>(
<nobr>&lt;Object&gt; <i>obj</i> )</nobr>
</code></td>

<td><code>Boolean</code></td>
<td>Returns <code><span class="literal">true</span></code> if the given object is an array.</td>
	</tr>
	<tr>
<td><code><b>trim</b>(
<nobr>&lt;String&gt; <i>str</i> )</nobr>
</code></td>

<td><code>String</code></td>
<td>Trims the whitespace from both ends of the string and returns the result.</td>
	</tr>
</table>

<h3>Properties</h3>

<table data-id='util'>
	<tr>
<th>Property</th>
<th>Type</th>
<th>Description</th>
	</tr>
	<tr>
<td><code><b>emptyImageUrl</b></code></td>
<td><code>String</code></td>
<td>Data URI string containing a base64-encoded empty GIF image. Used as a hack to free memory from unused images on WebKit-powered mobile devices (by setting image <code>src</code> to this string).</td>
	</tr>
</table>


